package top.kaoshanji.p2ch14a;

import top.kaoshanji.u1constant.FileConstant;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Random;

/**
 * 代码清单-p2ch14a-405页b：BasicQueue的生产者
 * author kaoshanji
 * ^_^
 * create time 2025/2/22 18:10
 */
public class BasicQueueProducer {

    public static void main(String[] args) throws IOException, InterruptedException {

        BasicQueue queue = new BasicQueue(FileConstant.BASIC_QUEUE_ROOT_PATH, "task");
        int i = 0;
        Random rnd = new Random();
        while (true) {
            String msg = new String("task-"+(i++));
            queue.enqueue(msg.getBytes(StandardCharsets.UTF_8));

            System.out.println("produce: " + msg);
            Thread.sleep(rnd.nextInt(1000));
        }

    }



}
